package com.habdqn.studentmanager.converter;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;

public class IntegerConverter implements Converter<String, Integer> {
	
	private static Logger logger = LoggerFactory.getLogger(IntegerConverter.class);
	
	@Override
	public Integer convert(String source) {
		Integer value = null;
		
		// 先判断
		if (StringUtils.isEmpty(source)) {
			
			return value;
		}
		
		try {
			value=Integer.valueOf(source);
		}
		catch (NumberFormatException e) {
			logger.debug("{} 转换 Integer 出错.", source, e);
		}
		return value;
	}

}
